home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Code Resources / SliderCDEF 1.0 / SliderCDEF Source ƒ / SliderThumbControl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-10  |  1.6 KB  |  47 lines  |  [TEXT/KAHL]

  1. #include "SliderCDEF.h"
  2.  
  3. // SliderThumbControl
  4. //
  5. // Calculates the parameters for dragging the indicator. This routine is not
  6. // necessary for this slider, since dragging is performed by the CDEF, not
  7. // the control manager.
  8. void SliderThumbControl( short varCode, ControlHandle theControl, long param )
  9. {
  10.     Point        thePoint;
  11.     Rect        thumbRect;
  12.     long        thumbHalfWidth;
  13.     long        offset;
  14.  
  15.     // Get the point where the user clicked from the limitRect topLeft point.
  16.     thePoint.h = ((ThumbCntlRecPtr)param)->limitRect.left;
  17.  
  18.     // Calculate the thumb rectangle.
  19.     thumbRect = CalcThumbRect( theControl );
  20.  
  21.     // Calculate the horizontal distance into the thumb from the left edge.
  22.     offset = thePoint.h - thumbRect.left;
  23.  
  24.     // Calculate half the width of the thumb.
  25.     thumbHalfWidth = (thumbRect.right - thumbRect.left)/2;
  26.  
  27.     // Equate the limitRect with the control's rectangle.
  28.     ((ThumbCntlRecPtr)param)->limitRect = (**theControl).contrlRect;
  29.  
  30.     // Inset the limitRect to account for interior borders of the track.
  31.     InsetRect( &((ThumbCntlRecPtr)param)->limitRect, 1, 1 );
  32.  
  33.     // Add the offset into the thumb to the left edge of the limitRect.
  34.     ((ThumbCntlRecPtr)param)->limitRect.left += (offset);
  35.  
  36.     // Subtract the opposite offset into the thumb from the right edge of the limitRect.
  37.     ((ThumbCntlRecPtr)param)->limitRect.right -= (thumbHalfWidth*2 - offset);
  38.  
  39.     // Equate the slopRect and the limitRect.
  40.     ((ThumbCntlRecPtr)param)->slopRect  = ((ThumbCntlRecPtr)param)->limitRect;
  41.  
  42.     // Expand the slopRect.
  43.     InsetRect( &((ThumbCntlRecPtr)param)->slopRect, -50, -30 );
  44.  
  45.     // Constrain dragging to the horizontal axis.
  46.     ((ThumbCntlRecPtr)param)->axis = hAxisOnly;
  47. }